<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\HousePurchase;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class HousePurchaseController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new HousePurchase(), function (Grid $grid) {
//            $grid->column('id')->sortable();
            $grid->column('house_id','房源id');
            $grid->column('house_logo','房源logo')->image('');
            $grid->column('house_tittle','团购标题');
            $grid->column('house_address','楼盘地址');
            $grid->column('start_date','开始时间');
            $grid->column('stop_date','结束时间');
            $grid->column('group_introduce','团购介绍');
            $grid->column('broker_id','经纪人id');
            $grid->column('number','团购人数');
            $grid->column('state','状态')->using(['1'=>'开启','0'=>'未开启']);
            $grid->column('created_at');
//            $grid->column('updated_at')->sortable();
            $grid->enableDialogCreate();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new HousePurchase(), function (Show $show) {
//            $show->field('id');
            $show->field('house_id');
            $show->field('house_logo');
            $show->field('house_tittle');
            $show->field('house_address');
            $show->field('start_date');
            $show->field('stop_date');
            $show->field('group_introduce');
            $show->field('broker_id');
            $show->field('number');
            $show->field('state');
//            $show->field('created_at');
//            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new HousePurchase(), function (Form $form) {
//            $form->display('id');
            $form->text('house_id');
            $form->image('house_logo');
            $form->text('house_tittle');
            $form->text('house_address');
            $form->text('start_date');
            $form->text('stop_date');
            $form->text('group_introduce');
            $form->text('broker_id');
            $form->text('number');
            $form->text('state');
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
